package jp.ac.u_tokyo.dch.core.db;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.DatabaseMetaData;
import java.sql.Date;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Time;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import jp.ac.u_tokyo.dch.core.exceptions.DBException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * PreparedStatement ラッパクラス
 *
 * @version 1.1
 */
public class CustomPreparedStatement {

	/** ロガー */
	private static Log logger = LogFactory.getLog(CustomPreparedStatement.class);

	/** PreparedStatement */
	private PreparedStatement stmt = null;

	/**
	 * コンストラクタ
	 * @param stmt PreparedStatement
	 */
	public CustomPreparedStatement(PreparedStatement stmt) {

		this.stmt = stmt;
	}

	public void addBatch() throws DBException {

		try {
			this.stmt.addBatch();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void clearParameters() throws DBException {

		try {
			this.stmt.clearParameters();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public boolean execute() throws DBException {

		try {
			return this.stmt.execute();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet executeQuery() throws DBException {

		try {
			return new CustomResultSet(this.stmt.executeQuery());
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate() throws DBException {

		try {
			return this.stmt.executeUpdate();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public ResultSetMetaData getMetaData() throws DBException {

		try {
			return this.stmt.getMetaData();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public ParameterMetaData getParameterMetaData() throws DBException {

		try {
			return this.stmt.getParameterMetaData();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setArray(int i, Array x) throws DBException {

		try {
			this.stmt.setArray(i, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setAsciiStream(int parameterIndex, InputStream x, int length)
			throws DBException {
		try {
			this.stmt.setAsciiStream(parameterIndex, x, length);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setBigDecimal(int parameterIndex, BigDecimal x)
			throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + x.toString() + "]");
			this.stmt.setBigDecimal(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setBinaryStream(int parameterIndex, InputStream x, int length)
			throws DBException {

		try {
			this.stmt.setBinaryStream(parameterIndex, x, length);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setBlob(int i, Blob x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(i) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setBlob(i, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setBoolean(int parameterIndex, boolean x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setBoolean(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setByte(int parameterIndex, byte x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setByte(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setBytes(int parameterIndex, byte[] x) throws DBException {

		try {
			StringBuffer buf = new StringBuffer();
			for ( int i=0; i<x.length; i++) {
				buf.append(x[i]);
			}
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setBytes(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setCharacterStream(int parameterIndex, Reader reader, int length)
			throws DBException {

		try {
			this.stmt.setCharacterStream(parameterIndex, reader, length);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setClob(int i, Clob x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(i) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setClob(i, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setDate(int parameterIndex, Date x) throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "]");

			this.stmt.setDate(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setDate(int parameterIndex, Date x, Calendar cal)
			throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "] 付帯惁E��[Calendar.getTimeZone().getDisplayName()]=[" + cal.getTimeZone().getDisplayName() + "]");

			this.stmt.setDate(parameterIndex, x, cal);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setDouble(int parameterIndex, double x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setDouble(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setFloat(int parameterIndex, float x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setFloat(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setInt(int parameterIndex, int x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setInt(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setLong(int parameterIndex, long x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setLong(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setNull(int parameterIndex, int sqlType) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 NULLが設定されてぁE��す。付帯惁E�� [sqlType]=[" + String.valueOf(sqlType) + "]");
			this.stmt.setNull(parameterIndex, sqlType);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setNull(int paramIndex, int sqlType, String typeName)
			throws DBException {

		try {
			logger.debug("[" + String.valueOf(paramIndex) + "]番目 NULLが設定されてぁE��す。付帯惁E�� [sqlType]=[" + String.valueOf(sqlType) + "] [typeName]=[" + String.valueOf(typeName) + "]");
			this.stmt.setNull(paramIndex, sqlType,typeName);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setObject(int parameterIndex, Object x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setObject(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setObject(int parameterIndex, Object x, int targetSqlType)
			throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "] 付帯惁E��[targetSqlType]=[" + String.valueOf(targetSqlType) + "}");
			this.stmt.setObject(parameterIndex, x, targetSqlType);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setObject(int parameterIndex, Object x, int targetSqlType,
			int scale) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "] 付帯惁E��[targetSqlType]=[" + String.valueOf(targetSqlType) + "] [scale]=[" + String.valueOf(scale) + "]");
			this.stmt.setObject(parameterIndex, x, targetSqlType, scale);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setRef(int i, Ref x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(i) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setRef(i, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setShort(int parameterIndex, short x) throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setShort(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setString(int parameterIndex, String x) throws DBException  {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");
			this.stmt.setString(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	/**
	 * Like検索用String設定関数
	 *
	 * @param parameterIndex
	 * @param x
	 * @param pattern 0:前方一致 1:後方一致 それ以夁E前方後方検索
	 * @throws DBException
	 */
	public void setStringforLike(int parameterIndex, String x, int pattern) throws DBException  {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + String.valueOf(x) + "]");

			DatabaseMetaData meta = this.getConnection().getMetaData();
			String escaping = meta.getSearchStringEscape();
			String x2 = null;
			for (int i=0; i<x.length(); i++) {
				if ( "%".equals(String.valueOf(x.charAt(i)))
						|| "_".equals(String.valueOf(x.charAt(i))) ) {
					if ( null == x2 ) {
						x2 = escaping;
					} else {
						x2 += escaping;
					}

				}
				if ( null == x2 ) {
					x2 = String.valueOf(x.charAt(i));
				} else {
					x2 += String.valueOf(x.charAt(i));
				}

			}

			if ( pattern == 0 ) {
				if ( x2 != null ) {
					x2 = "%" + x2;
				}
			} else if ( pattern == 1 ) {
				if ( x2 != null ) {
					x2 += "%";
				}
			} else {
				if ( x2 != null ) {
					x2 = "%" + x2;
					x2 += "%";
				}
			}

			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 置換値=[" + String.valueOf(x2) + "]");

			this.stmt.setString(parameterIndex, x2);

		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setTime(int parameterIndex, Time x) throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "]");
			stmt.setTime(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setTime(int parameterIndex, Time x, Calendar cal)
			throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "] 付帯惁E��[Calendar.getTimeZone().getDisplayName()]=[" + cal.getTimeZone().getDisplayName() + "]");
			stmt.setTime(parameterIndex, x, cal);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setTimestamp(int parameterIndex, Timestamp x)
			throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "]");
			stmt.setTimestamp(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
			throws DBException {

		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[" + format.format(x) + "] 付帯惁E��[Calendar.getTimeZone().getDisplayName()]=[" + cal.getTimeZone().getDisplayName() + "]");
			stmt.setTimestamp(parameterIndex, x, cal);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setURL(int parameterIndex, URL x) throws DBException {

		try {
			StringBuffer buf = new StringBuffer();
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getAuthority=[" + x.getAuthority() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getDefaultPort=[" + String.valueOf(x.getDefaultPort()) + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getFile=[" + x.getFile() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getHost=[" + x.getHost() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getPath=[" + x.getPath() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getPort=[" + String.valueOf(x.getPort()) + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getProtocol=[" + x.getProtocol() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getQuery=[" + x.getQuery() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getRef=[" + x.getRef() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "getUserInfo=[" + x.getUserInfo() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "toExternalForm=[" + x.toExternalForm() + "]");
			buf.append(String.valueOf(System.getProperty("line.separator")) + "toString=[" + x.toString() + "]");

			logger.debug("[" + String.valueOf(parameterIndex) + "]番目 値=[URLの値を以下に展開]" + buf.toString());
			stmt.setURL(parameterIndex, x);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	@SuppressWarnings("deprecation")
	public void setUnicodeStream(int parameterIndex, InputStream x, int length)
			throws DBException {

		try {
			logger.debug("[" + String.valueOf(parameterIndex) + "]番目に、InputStreamがセチE��されました。length=[" + String.valueOf(length) + "]");
			stmt.setUnicodeStream(parameterIndex, x, length);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void addBatch(String sql) throws DBException {

		try {
			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql);
			stmt.addBatch(sql);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void cancel() throws DBException {

		try {
			stmt.cancel();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void clearBatch() throws DBException {

		try {
			stmt.clearBatch();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void clearWarnings() throws DBException {

		try {
			stmt.clearWarnings();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}


	}

	public void close() throws DBException {

		try {
			logger.info("PreparedStatement [ Close ] HashCode :[" + String.valueOf(stmt.hashCode()) + "]");
			stmt.close();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}


	}

	public boolean execute(String sql) throws DBException {

		try {
			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql);
			return stmt.execute(sql);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean execute(String sql, int autoGeneratedKeys)
			throws DBException {

		try {
			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + String.valueOf(System.getProperty("line.separator") ) + "autoGeneratedKeys=[" + String.valueOf(autoGeneratedKeys) + "]");
			return stmt.execute(sql,autoGeneratedKeys);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean execute(String sql, int[] columnIndexes) throws DBException {

		try {

			StringBuffer buf = new StringBuffer();
			for (int i=0; i<columnIndexes.length; i++ ) {
				buf.append(System.getProperty("line.separator"));
				buf.append("columnIndexes[" + String.valueOf(i) + "]=[" + String.valueOf(columnIndexes[i]) + "]");
			}

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + buf.toString());
			return stmt.execute(sql,columnIndexes);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public boolean execute(String sql, String[] columnNames)
			throws DBException {

		try {

			StringBuffer buf = new StringBuffer();
			for (int i=0; i<columnNames.length; i++ ) {
				buf.append(System.getProperty("line.separator"));
				buf.append("columnNames[" + String.valueOf(i) + "]=[" + columnNames[i] + "]");
			}

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + buf.toString());
			return stmt.execute(sql,columnNames);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int[] executeBatch() throws DBException {

		try {
			return stmt.executeBatch();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public CustomResultSet executeQuery(String sql) throws DBException {

		try {

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql);
			return new CustomResultSet(stmt.executeQuery(sql));

		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public int executeUpdate(String sql) throws DBException {

		try {

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql);
			return stmt.executeUpdate(sql);

		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql, int autoGeneratedKeys)
			throws DBException {

		try {

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + String.valueOf(System.getProperty("line.separator") ) + "autoGeneratedKeys=[" + String.valueOf(autoGeneratedKeys) + "]");
			return stmt.executeUpdate(sql, autoGeneratedKeys);

		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public int executeUpdate(String sql, int[] columnIndexes)
			throws DBException {

		try {
			StringBuffer buf = new StringBuffer();
			for (int i=0; i<columnIndexes.length; i++ ) {
				buf.append(System.getProperty("line.separator"));
				buf.append("columnIndexes[" + String.valueOf(i) + "]=[" + String.valueOf(columnIndexes[i]) + "]");
			}

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + buf.toString());
			return stmt.executeUpdate(sql,columnIndexes);

		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int executeUpdate(String sql, String[] columnNames)
			throws DBException {

		try {

			StringBuffer buf = new StringBuffer();
			for (int i=0; i<columnNames.length; i++ ) {
				buf.append(System.getProperty("line.separator"));
				buf.append("columnNames[" + String.valueOf(i) + "]=[" + columnNames[i] + "]");
			}

			logger.debug("■■■■■SQL■■■■■" + String.valueOf(System.getProperty("line.separator"))  + sql + buf.toString());

			return stmt.executeUpdate(sql, columnNames);

		} catch ( SQLException e ) {

			logger.error("ERROR",e);
			throw new DBException();

		}

	}

	public DBConnection getConnection() throws DBException {

		try {

			return new DBConnection(stmt.getConnection());

		} catch ( SQLException e ) {

			logger.error("ERROR",e);
			throw new DBException();

		}

	}

	public int getFetchDirection() throws DBException {

		try {
			return stmt.getFetchDirection();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getFetchSize() throws DBException {

		try {
			return stmt.getFetchSize();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet getGeneratedKeys() throws DBException {

		try {
			return new CustomResultSet(stmt.getGeneratedKeys());
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getMaxFieldSize() throws DBException {

		try {
			return stmt.getMaxFieldSize();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getMaxRows() throws DBException {

		try {
			return stmt.getMaxRows();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean getMoreResults() throws DBException {

		try {
			return stmt.getMoreResults();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public boolean getMoreResults(int current) throws DBException {

		try {
			return stmt.getMoreResults(current);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getQueryTimeout() throws DBException {

		try {
			return stmt.getQueryTimeout();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public CustomResultSet getResultSet() throws DBException {

		try {
			return new CustomResultSet(stmt.getResultSet());
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetConcurrency() throws DBException {

		try {
			return stmt.getResultSetConcurrency();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetHoldability() throws DBException {

		try {
			return stmt.getResultSetHoldability();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getResultSetType() throws DBException {

		try {
			return stmt.getResultSetType();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public int getUpdateCount() throws DBException {

		try {
			return stmt.getUpdateCount();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public SQLWarning getWarnings() throws DBException {

		try {
			return stmt.getWarnings();
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}
	}

	public void setCursorName(String name) throws DBException {

		try {
			logger.debug("CursorName=[" + String.valueOf(name) + "]");
			logger.debug("cursorName=[" + name + "]");
			stmt.setCursorName(name);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setEscapeProcessing(boolean enable) throws DBException {

		try {
			logger.debug("EscapeProcessing=[" + String.valueOf(enable) + "]");
			stmt.setEscapeProcessing(enable);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setFetchDirection(int direction) throws DBException {

		try {
			logger.debug("FetchDirection=[" + String.valueOf(direction) + "]");
			stmt.setFetchDirection(direction);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setFetchSize(int rows) throws DBException {

		try {
			logger.debug("fetchSize=[" + String.valueOf(rows) + "]");
			stmt.setFetchSize(rows);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setMaxFieldSize(int max) throws DBException {

		try {
			logger.debug("maxFieldSize=[" + String.valueOf(max) + "]");
			stmt.setMaxFieldSize(max);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setMaxRows(int max) throws DBException {

		try {
			logger.debug("maxRows=[" + String.valueOf(max) + "]");
			stmt.setMaxRows(max);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

	public void setQueryTimeout(int seconds) throws DBException {

		try {
			logger.debug("queryTimeout=[" + String.valueOf(seconds) + "]");
			stmt.setQueryTimeout(seconds);
		} catch ( SQLException e ) {
			logger.error("ERROR",e);
			throw new DBException();
		}

	}

}
